package indzcraft.calc;
import java.util.HashMap;


public class Talents {
	
	private String spec = "";
	// Assassination Tree
	private HashMap<String,Integer> assa = new HashMap<String,Integer>();
	private String[] assa_names = new String[19];
	
	// Combat Tree
	private HashMap<String,Integer> combat = new HashMap<String,Integer>();
	private String[] combat_names = new String[19];
	
	// Subtlety Tree
	private HashMap<String,Integer> subtlety = new HashMap<String,Integer>();
	private String[] subtlety_names = new String[19];
	
	// Passives
	//public HashMap<String,Integer> passive = new HashMap<String,Integer>();
	// globals
	String ep = "";
	
	//public Talents() {};
	
	public Talents(String tree1, String tree2, String tree3)
	{
		fillTrees();
		
		//check_tree_length(tree1,tree2,tree3);
		
		compute_assassination_talents(tree1);
		compute_combat_talents(tree2);
		compute_subtlety_talents(tree3);
	}
	
	public boolean isCombat(){
		return (spec == "Combat") || checkLength(combat);
	}
	public boolean isAssa(){
		return (spec == "Assa") || checkLength(assa);
	}
	public boolean isSubtlety(){
		return (spec == "Subtlety") || checkLength(subtlety);
	}
	
	public int get(String name){
		try {
			if(combat.containsKey(name))
				return value(combat,name);
			else if(assa.containsKey(name))
				return value(assa,name);
			else if(subtlety.containsKey(name))
				return value(subtlety,name);
			else
				throw new Exception("Talent:" + name + "doesn't exist!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
	
	public HashMap<String,Integer> getCombat(){
		return combat;
	}
	public HashMap<String,Integer> getAssa(){
		return assa;
	}
	public HashMap<String,Integer> getSubtlety(){
		return assa;
	}
	
	private int value(HashMap<String,Integer> tree,String name){
		int value = tree.get(name);
		if(this.ep.equals(name)){
			if(value == 0)
				value++;
			else 
				value--;
		}
		return value;
	}
	
	
	private boolean checkLength(HashMap<String,Integer> tree){
		int sum = 0;
		for(String name : tree.keySet() ){
			sum += tree.get(name);
		}
		if (sum >= 31)
			return true;
		return false;
	}
	
	private void compute_assassination_talents(String tree)
	{
		for (int i = 0;i < tree.length(); i++){
			int p = Integer.parseInt(tree.substring(i, i+1));
			assa.put(assa_names[i], p);
		}
		if(checkLength(assa))
			spec = "Assa";
	}
	
	private void compute_combat_talents(String tree)
	{
		for (int i = 0;i < tree.length(); i++){
			int p = Integer.parseInt(tree.substring(i, i+1));
			combat.put(combat_names[i], p);
		}
		if(checkLength(combat))
			spec = "Combat";
	}
	
	private void compute_subtlety_talents(String tree)
	{
		for (int i = 0;i < tree.length(); i++){
			int p = Integer.parseInt(tree.substring(i, i+1));
			subtlety.put(subtlety_names[i], p);
		}
		if(checkLength(subtlety))
			spec = "Subtlety";
	}
	
	private void fillTrees() {
		//passive.put("vitality",1);
		//passive.put("ambidexterity", 1);
		
		assa_names[0] = "deadly_momentum";
		assa_names[1] = "coup_de_grace";
		assa_names[2] = "lethality";
		assa_names[3] = "ruthlessness";
		assa_names[4] = "quickening";
		assa_names[5] = "puncturing_wounds";
		assa_names[6] = "blackjack";
		assa_names[7] = "deadly_brew";
		assa_names[8] = "cold_blood";
		assa_names[9] = "vile_poisons";
		assa_names[10] = "deadened_nerves";
		assa_names[11] = "seal_fate";
		assa_names[12] = "murderous_intent";
		assa_names[13] = "overkill";
		assa_names[14] = "master_poisoner";
		assa_names[15] = "imp_ea";
		assa_names[16] = "cttc";
		assa_names[17] = "venomous_wounds";
		assa_names[18] = "vendetta";
		
		combat_names[0] = "imp_recuperate";
		combat_names[1] = "imp_sinister_strike";
		combat_names[2] = "precision";
		combat_names[3] = "imp_snd";
		combat_names[4] = "imp_sprint";
		combat_names[5] = "aggression";
		combat_names[6] = "imp_kick";
		combat_names[7] = "lightning_reflexes";
		combat_names[8] = "revealing_strike";
		combat_names[9] = "reinforced_leather";
		combat_names[10] = "imp_gouge";
		combat_names[11] = "combat_potency";
		combat_names[12] = "blade_twisting";
		combat_names[13] = "throwing_spec";
		combat_names[14] = "adrenaline_rush";
		combat_names[15] = "savage_combat";
		combat_names[16] = "bandits_guile";
		combat_names[17] = "restless_blades";
		combat_names[18] = "killing_spree";
		
		subtlety_names[0] = "nightstalker";
		subtlety_names[1] = "imp_ambush";
		subtlety_names[2] = "relentless_strikes";
		subtlety_names[3] = "elusiveness";
		subtlety_names[4] = "waylay";
		subtlety_names[5] = "opportunity";
		subtlety_names[6] = "initiative";
		subtlety_names[7] = "energetic_recovery";
		subtlety_names[8] = "find_weakness";
		subtlety_names[9] = "hemorrhage";
		subtlety_names[10] = "honor_among_thieves";
		subtlety_names[11] = "premeditation";
		subtlety_names[12] = "enveloping_shadows";
		subtlety_names[13] = "cheat_death";
		subtlety_names[14] = "preparation";
		subtlety_names[15] = "sanguinary_vein";
		subtlety_names[16] = "sfss";
		subtlety_names[17] = "serrated_blades";
		subtlety_names[18] = "shadow_dance";
	}
	
	public String toString(){
		for(String name : assa.keySet()){
			System.out.println(name + " " + assa.get(name));
		}
		for(String name : combat.keySet()){
			System.out.println(name + " " + combat.get(name));
		}
		for(String name : subtlety.keySet()){
			System.out.println(name + " " + subtlety.get(name));
		}
		return super.toString();
	}
}
